<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>论文检索系统</title>

    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/css/mainstyle.css}">
</head>

<body>
    <div th:replace="common :: commonheader"></div>

    <div th:replace="common :: leftmenu"></div>

    <div class="right-content col-md-10">
        <form class="form-inline" th:action="@{/admin/findAllPapers}" method="post" style="margin-top: 20px;"
              onkeydown="if(event.keyCode===13){return false;}">
            <div class="search">
                <div class="form-group">
                    <label style="font-size: 25px">搜索：</label>
                    <input type="text" name="subTitle" id="subTitle" style="font-size: 20px; border-radius: 4px;
                border: 2px solid #ccc;" autocomplete="off">
                </div>
                <button type="submit" onclick="return search()" style="font-size: 20px;">检索</button>
            </div>
        </form>
    </div>

    <div class="right-content col-md-10" style="margin-top: 15px; margin-left: 15px;
    background-color: lightgrey; width: 1250px; height: 30px;" th:if="${subTitle} != 'null'">
        <div style="float: right; margin-top: 5px;">
            <a id="a_time" style="margin-right: 20px;" th:href="@{/admin/findAllPapers(currentPage='1',
            subTitle=${subTitle}, order='time')}">发表时间</a>
            <a id="a_download" th:href="@{/admin/findAllPapers(currentPage='1', subTitle=${subTitle},
            order='download')}">下载次数</a>
        </div>
    </div>

    <div class="right-content col-md-10" th:if="${subTitle} != 'null'" style="margin-top: 15px">
        <table class="table table-bordered" id="table-general-admin">
            <thead>
                <tr>
                    <th style="width: 80px;background-color: lightblue;">序号</th>
                    <th style="background-color: lightblue;">分类号</th>
                    <th style="width: 500px;background-color: lightblue;">论文名称</th>
                    <th style="width: 70px;background-color: lightblue;">作者</th>
                    <th style="width: 500px;background-color: lightblue;">关键字</th>
                    <th style="width: 150px;background-color: lightblue;">论文类别</th>
                    <th style="width: 170px;background-color: lightblue;">发表时间</th>
                    <th style="width: 170px;background-color: lightblue;">下载次数</th>
                    <th style="width: 150px;background-color: lightblue;">下载</th>
                    <th style="width: 300px;background-color: lightblue;">操作</th>
                </tr>
            </thead>
            <tbody>
                <tr th:each="paperInfo : ${paperInfoList}" th:switch="${session.loginer}">
                    <td>[[${paperInfoStat.count + (pageInfo.pageNum - 1) * pageInfo.pageSize}]]</td>
                    <td>[[${paperInfo.classnum}]]</td>
                    <td>[[${paperInfo.title}]]</td>
                    <td>[[${paperInfo.author}]]</td>
                    <td>[[${paperInfo.keyword}]]</td>
                    <td>[[${paperInfo.type}]]</td>
                    <td>[[${paperInfo.time}]]</td>
                    <td>[[${paperInfo.download}]]</td>
                    <td><a th:href="@{/paperinfo/downloadPaper(id=${paperInfo.id}, address=${paperInfo.address})}">
                        点此下载</a></td>
                    <td>
                        <a th:href="@{/admin/findPaperById(id=${paperInfo.id})}">修改</a>
                        <a th:href="@{/admin/deletePaper(id=${paperInfo.id})}" onclick="return deletePaper()">删除</a>
                        <a th:href="@{/paperinfo/showPaperInfo(id=${paperInfo.id})}">查看</a>
                    </td>
                </tr>
            </tbody>
        </table>

        <div class="row-fluid">
            <div>
                当前第[[${pageInfo.pageNum}]]页  总计[[${pageInfo.pages}]]页  共[[${pageInfo.total}]]条记录
            </div>
            <div>
                <ul class="pagination" th:if="${pageInfo.total == 0 || (pageInfo.isFirstPage && pageInfo.isLastPage)}">
                </ul>
                <ul class="pagination" th:if="${pageInfo.isFirstPage && !pageInfo.isLastPage}">
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.nextPage}, subTitle=${subTitle},
                    order=${order})}">下一页</a></li>
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.pages}, subTitle=${subTitle},
                    order=${order})}">尾页</a></li>
                </ul>
                <ul class="pagination" th:if="${pageInfo.isLastPage && !pageInfo.isFirstPage && pageInfo.total != 0}">
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.firstPage}, subTitle=${subTitle},
                    order=${order})}">首页</a></li>
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.prePage}, subTitle=${subTitle},
                    order=${order})}">上一页</a></li>
                </ul>
                <ul class="pagination" th:if="${!pageInfo.isLastPage && !pageInfo.isFirstPage}">
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.firstPage}, subTitle=${subTitle},
                    order=${order})}">首页</a></li>
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.prePage}, subTitle=${subTitle},
                    order=${order})}">上一页</a></li>
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.nextPage}, subTitle=${subTitle},
                    order=${order})}">下一页</a></li>
                    <li><a th:href="@{/admin/findAllPapers(currentPage=${pageInfo.pages}, subTitle=${subTitle},
                    order=${order})}">尾页</a></li>
                </ul>
            </div>
        </div>
    </div>
</body>

<script th:inline="javascript">
    document.getElementById("li_head1").className = "active";

    document.getElementById("a_search").style.backgroundColor = "#4CAF50";
    document.getElementById("a_search").style.color = "white";

    let title = [[${subTitle}]].toString();
    let table = document.getElementById("table-general-admin");
    let row = table.rows.length;
    if (row != null) {
        for (let i = 1; i < row; i++) {
            for (let j = 2; j <= 4; j++) {
                let ptitle = table.rows[i].cells[j];
                let ptitles = ptitle.innerHTML;
                let values = ptitles.split(title);
                ptitle.innerHTML = values.join('<span style="color: red; font-weight: bold">' + title + '</span>');
            }
        }
    }

    let order = [[${order}]].toString();
    if (order === "time") {
        document.getElementById("a_time").style.color = "blue";
        document.getElementById("a_time").style.fontWeight = "bold";
    }
    else {
        document.getElementById("a_download").style.color = "blue";
        document.getElementById("a_download").style.fontWeight = "bold";
    }

    function search() {
        let subTitle = document.getElementById("subTitle").value;
        if (subTitle === "") {
            alert("请输入检索内容！");
            return false;
        }
        return true;
    }

    function deletePaper() {
        let r = confirm("确定删除此论文？");
        return r === true;
    }
</script>

</html>